<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const arr = [
      {
        name: '张三',
        id: 1,
        pid: ''
      },
      {
        name: '李四',
        id: 2,
        pid: ''
      },
      {
        name: '张三三',
        id: 3,
        pid: 1
      },
      {
        name: '张三三三',
        id: 4,
        pid: 3
      },
      {
        name: '李四四',
        id: 5,
        pid: 2
      },
    ]
    function add (pid){
      const dss = []
      this.arr.forEach(item => {
        if(item.pid === pid) {
          const chs = add(item.id)
          if(chs.length)
        }
      });
    }
  </script>
</body>
</html>